package com.tensquare.article.controller;


import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Created by : 大萝卜
* Date: 2020-4-4        处理公共异常方法
*/

@Slf4j
@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handler(Exception e){
        //处理空指针
        if (e instanceof NullPointerException){
            log.info("空指针问题，请查看值问题！");
            return new Result(false, StatusCode.ERROR,e.getMessage());
        }
        System.out.println("调用处理公共异常方法");
        log.info("调用处理公共异常方法:{}",this.getClass().getMethods());
        return new Result(false, StatusCode.ERROR,e.getMessage());
    }
}
